package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口Api注解")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }

    /**
     * 新增床位
     * @param abc
     * @return
     */
    @PostMapping("/create")
    @ApiOperation(value = "新增床位", notes = "传入床位对象")
    public ResponseResult<String> createBed(@RequestBody BedDto abc){
        //调用业务层
        bedService.addBed(abc);
        return ResponseResult.success();
    }

    /**
     * 通过id查询床位
     * @param id
     * @return
     */
    @GetMapping("/read/{id}")
    public ResponseResult<BedVo> getById(@PathVariable Long id){
        BedVo vo = bedService.getById(id);
        return ResponseResult.success(vo);
    }

    /**
     * 更新床位
     * @param bedDto
     * @return
     */
    @PutMapping("/update")
    public ResponseResult update(@RequestBody BedDto bedDto){
        bedService.updateById(bedDto);
        return ResponseResult.success();
    }

    /**
     * 通过id删除床位
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("通过id删除床位")
    public ResponseResult<BedVo> deleteById(@ApiParam(required = true, value = "床位id") @PathVariable Long id){
        bedService.deleteById(id);
        return ResponseResult.success();
    }
}
